package model;

public class MyVector {
	private double x;
	private double y;
	
	public MyVector(double x,double y){
		this.x = x;
		this.y = y;
	}
	
	public double getX() {
		return x;
	}
	
	public void setX(double x) {
		this.x = x;
	}
	
	public double getY() {
		return y;
	}
	
	public void setY(double y) {
		this.y = y;
	}
	
	public MyVector copy(){
		return new MyVector(x,y);
	}
	
	public double length(){
		return Math.sqrt(x*x+y*y);
	}
	
	public double sqrLength(){
		return x*x+y*y;
	}
	
	public MyVector normalize(){
		double inv = 1/length(); 
		return new MyVector(x * inv, y * inv);
	}
	
	public MyVector negate(){
		return new MyVector(-x, -y);
	}
	
	public MyVector add(MyVector v){
		return new MyVector(this.x + v.x, this.y + v.y);
	}
	
	public MyVector subtract(MyVector v) { 
    	return new MyVector(this.x - v.x, this.y - v.y);
    }
	
	public MyVector multiply(double f) { 
		return new MyVector(this.x * f, this.y * f);
	}
	
	public MyVector divide(double f) { 
		double invf = 1/f; 
		return new MyVector(this.x * invf, this.y * invf);
	}
	
	public double dot(MyVector v) { 
		return this.x * v.x + this.y * v.y;
	}
	
	public String toString(){
		StringBuilder sb = new StringBuilder("");
		sb.append("Vector x:");
		sb.append(x);
		sb.append(" ");
		sb.append("y:");
		sb.append(y);
		return sb.toString();
	}
}
